
config:
  user.user-data: |
    #cloud-config
    packages:
      - va-driver-all
      - vdpau-driver-all
      - qtwayland5
      - at-spi2-core
      - xdg-utils
      - pulseaudio-utils
      - x11-apps
      - dbus-x11
    write_files:
      - path: /etc/systemd/system/setup-forward-symlinks.service
        content: |
          [Unit]
          After=sysinit.target

          [Service]
          Type=oneshot
          ExecStart=/opt/setup-forward-symlinks.sh

          [Install]
          WantedBy=multi-user.target
      - path: /opt/setup-forward-symlinks.sh
        permissions: '0755'
        content: |
          #!/bin/bash
          USER_UID=1000 # Replace this with your container user UID
          RUNTIME_DIR=/run/user/$USER_UID
          mkdir -p $RUNTIME_DIR
          chmod 700 $RUNTIME_DIR
          chown $USER_UID:$USER_UID $RUNTIME_DIR
          mkdir -p /tmp/.X11-unix
          ln -sf /mnt/x11-socket-x0 /tmp/.X11-unix/X0
          chmod -R 776 /tmp/.X11-unix/X0
          chown -R $USER_UID:$USER_UID /tmp/.X11-unix/X0
          ln -sf /mnt/x11-socket-x1 /tmp/.X11-unix/X1
          chmod -R 776 /tmp/.X11-unix/X1
          chown -R $USER_UID:$USER_UID /tmp/.X11-unix/X1
    runcmd:
      - systemctl daemon-reload
      - systemctl enable setup-forward-symlinks.service
      - systemctl --no-block start setup-forward-symlinks.service
      # Replace '/home/ubuntu' with your home directory
      - 'echo "export DISPLAY=:1" >> /home/ubuntu/.profile'
      - 'echo "export PULSE_SERVER=unix:/home/ubuntu/pulse-native" | tee --append /home/ubuntu/.profile'
      - 'sed -i "s/; enable-shm = yes/enable-shm = no/g" /etc/pulse/client.conf'
      - dpkg --add-architecture i386
      - apt update
devices:
  gpu:
    gid: "13" # GID of 'video' group
    type: gpu
  x11-socket-x0:
    bind: container
    connect: unix:/tmp/.X11-unix/X0 # Replace 'X0' with your X display ($DISPLAY)
    listen: unix:/mnt/x11-socket-x0
    type: proxy
    security.uid: "1000" # Replace this with your host user UID
    security.gid: "1000" # Replace this with your host user GID
    uid: "1000" # Replace this with your container user UID
    gid: "1000" # Replace this with your container user GID
  x11-socket-x1:
    bind: container
    connect: unix:/tmp/.X11-unix/X1 # Replace 'X0' with your X display ($DISPLAY)
    listen: unix:/mnt/x11-socket-x1
    type: proxy
    security.uid: "1000" # Replace this with your host user UID
    security.gid: "1000" # Replace this with your host user GID
    uid: "1000" # Replace this with your container user UID
    gid: "1000" # Replace this with your container user GID
  PASocket:
    bind: container
    connect: unix:/run/user/1000/pulse/native
    listen: unix:/home/ubuntu/pulse-native
    security.gid: "1000"
    security.uid: "1000"
    uid: "1000"
    gid: "1000"
    mode: "0777"
    type: proxy
